<template>
  <div class="legal-consult">
    <!--    法律咨询查询表单-->
    <div class="search">
      <div class="title">法律咨询列表</div>
      <el-form :inline="true" :model="searchForm" label-width="100px" class="demo-form-inline" size="mini"
               ref="search">
<!--        <el-form-item label='咨询编号' prop="rec_id">-->
<!--          <el-input v-model="searchForm.rec_id" placeholder="请填入数字"-->
<!--                    oninput="if(isNaN(value)){value=value.replace(/[^0-9]/g,'')}" clearable></el-input>-->
<!--        </el-form-item>-->
        <el-form-item label='服务商id' prop="ser_id">
          <el-input v-model="searchForm.ser_id" placeholder="请填入数字"
                    oninput="if(isNaN(value)){value=value.replace(/[^0-9]/g,'')}" clearable></el-input>
        </el-form-item>
        <el-form-item label='订单id' prop="or_id">
          <el-input v-model="searchForm.or_id" placeholder="请填入数字"
                    oninput="if(isNaN(value)){value=value.replace(/[^0-9]/g,'')}" clearable></el-input>
        </el-form-item>
        <el-form-item label='咨询标题' prop="rec_title">
          <el-input v-model="searchForm.rec_title" clearable></el-input>
        </el-form-item>
<!--        <el-form-item label='咨询内容' prop="rec_con">-->
<!--          <el-input v-model="searchForm.rec_con" clearable></el-input>-->
<!--        </el-form-item>-->
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
          <el-button @click="resetForm('search')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <!--   法律咨询列表-->
    <el-table
      :data="showTableData"
      stripe
      style="width: 100%"
      size="mini">
      <el-table-column
        type="index"
        width="50"
        label="#">
      </el-table-column>
      <el-table-column
        prop="rec_id"
        label="咨询编号">
      </el-table-column>
      <el-table-column
        prop="or_id"
        label="订单id">
      </el-table-column>
      <el-table-column
        prop="ser_id"
        label="服务方ID">
      </el-table-column>
      <el-table-column
        prop="rec_title"
        label="咨询标题"
        width="200">
      </el-table-column>
      <el-table-column
        width="300"
        prop="rec_con"
        label="咨询内容">
      </el-table-column>
      <el-table-column
        prop="rec_price"
        label="价格">
      </el-table-column>
    </el-table>

    <!--      分页-->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[5, 10, 20, 30]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>

  </div>
</template>

<script>
import {getRecourseByKey} from "@/network/business/legalConsult";

export default {
  name: "LegalConsult",
  created(){
    this.getConsultFromServe();
  },
  data(){
    return{
      searchForm:{  //法律咨询查询表单
        // rec_id:'', //咨询id
        // rec_con:'', //咨询内容
        ser_id: '',  //服务商id
        rec_title:'', //咨询标题
        or_id:'',  //订单id
      },
      currentPage: 1,  //当前页面
      pageSize:5,  //页面条数，默认为10条
      addDialogVisible: false,  //增加知识产权对话框
      tableData:[],  //服务器中请求的数据
      showTableData:[],  //分页的列表
    }
  },
  methods:{
    getConsultFromServe(){
      this.currentPage = 1;
      getRecourseByKey(this.searchForm).then(res=>{
        if(res.status==200){
          this.tableData=res.data;
          this.getTableData();
        }
      })
    },
    resetForm(formName){  //重置查询表单
      this.$refs[formName].resetFields();
      this.getConsultFromServe();
    },
    onSubmit(){  //查询
      this.getConsultFromServe();
    },

    //分页操作
    handleSizeChange(val){  //每页条数变化
      this.pageSize =val;
      this.getTableData();
    },
    handleCurrentChange(val){  //当前页发生改变
      this.currentPage = val;
      this.getTableData();
    },
    getTableData(){  //获取数据
      let startIndex = (this.currentPage-1)*this.pageSize;
      let endIndex = startIndex+this.pageSize > this.tableData.length ? this.tableData.length : startIndex+this.pageSize;
      this.showTableData = this.tableData.slice(startIndex,endIndex);
    }
  },
  computed:{
    total(){ //总条数
      return this.tableData.length;
    }
  },
}
</script>

<style scoped>
.legal-consult{
  height: 100%;
}
.search{
  border: 1px solid #999999;
  border-radius: 3px;
  margin-bottom: 10px;
}
.title{
  color: white;
  background-color: rgb(55,75,118);
  font-size: 12px;
  height: 25px;
  line-height: 25px;
  padding-left:8px;
  margin-bottom: 10px;
}

</style>
